<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="网际层网际协议IP网际协议IP是TCP&#x2F;IP体系中两个最主要的协议之一. 与之配套使用的还有四个协议:  地址解析协议 ARP Address Resolution Protocol 逆地址解析协议 RARP Reverse Address Resolution Protocol 网际控制报文协议 ICMP Internet Control Message Protocol 网际组管理协">
<meta property="og:type" content="article">
<meta property="og:title" content="网际层">
<meta property="og:url" content="https://cheung0-bit.github.io/a5656a05d09c/index.html">
<meta property="og:site_name" content="Bruce Zhang&#39;s Blogs">
<meta property="og:description" content="网际层网际协议IP网际协议IP是TCP&#x2F;IP体系中两个最主要的协议之一. 与之配套使用的还有四个协议:  地址解析协议 ARP Address Resolution Protocol 逆地址解析协议 RARP Reverse Address Resolution Protocol 网际控制报文协议 ICMP Internet Control Message Protocol 网际组管理协">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/6-191106153044K1.gif">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/v2-13c1daebb7b5706a847f4e727d9dacde_r.jpg">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/2004486-20200510025702516-1476111227.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/2269756-20210825171143297-161791354.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220625161948298.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624165557945.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624201909104.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624202154348.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624202232812.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624203254275.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624203912640.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624204143794.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205214717.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205723172.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205745971.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205802040.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205810343.png">
<meta property="article:published_time" content="2022-06-25T13:02:12.000Z">
<meta property="article:modified_time" content="2022-11-25T06:51:00.159Z">
<meta property="article:author" content="张林">
<meta property="article:tag" content="计算机网络">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/6-191106153044K1.gif">
    
    
      
        
          <link rel="shortcut icon" href="/images/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
        
      
    
    <!-- title -->
    <title>网际层</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
      <link rel="alternate" href="/atom.xml" title="Bruce Zhang&#39;s Blogs" type="application/atom+xml" />
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 7.0.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/">Home</a></li><!--
     --><!--
       --><li><a href="/about/">About</a></li><!--
     --><!--
       --><li><a href="/archives/">Articles</a></li><!--
     --><!--
       --><li><a href="/categories/">Category</a></li><!--
     --><!--
       --><li><a href="/search/">Search</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="Previous post" href="/23e9d1f067f1/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="Next post" href="/e7adefa34d04/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="Back to top" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="Share post" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/a5656a05d09c/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/a5656a05d09c/&text=网际层"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/a5656a05d09c/&is_video=false&description=网际层"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=网际层&body=Check out this article: https://cheung0-bit.github.io/a5656a05d09c/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/a5656a05d09c/&name=网际层&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/a5656a05d09c/&t=网际层"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E5%B1%82"><span class="toc-number">1.</span> <span class="toc-text">网际层</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E5%8D%8F%E8%AE%AEIP"><span class="toc-number">1.1.</span> <span class="toc-text">网际协议IP</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%99%9A%E6%8B%9F%E4%BA%92%E8%81%94%E7%BD%91%E7%BB%9C"><span class="toc-number">1.1.1.</span> <span class="toc-text">虚拟互联网络</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#IP%E6%95%B0%E6%8D%AE%E5%8C%85%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.1.2.</span> <span class="toc-text">IP数据包格式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E7%B1%BB%E7%9A%84IP%E5%9C%B0%E5%9D%80"><span class="toc-number">1.1.3.</span> <span class="toc-text">分类的IP地址</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AE-ARP-%E4%B8%8E%E9%80%86%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AERARP"><span class="toc-number">1.1.4.</span> <span class="toc-text">地址解析协议 ARP 与逆地址解析协议RARP</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E6%8A%A5%E6%96%87%E6%8E%A7%E5%88%B6%E5%8D%8F%E8%AE%AEICMP"><span class="toc-number">1.1.5.</span> <span class="toc-text">网际报文控制协议ICMP</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B7%AF%E7%94%B1%E9%80%89%E6%8B%A9%E5%8D%8F%E8%AE%AE"><span class="toc-number">1.2.</span> <span class="toc-text">路由选择协议</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">1.2.1.</span> <span class="toc-text">基本概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E6%B2%BB%E7%B3%BB%E7%BB%9FAS-Autonomous-System"><span class="toc-number">1.2.2.</span> <span class="toc-text">自治系统AS(Autonomous System)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E9%83%A8%E7%BD%91%E5%85%B3%E5%8D%8F%E8%AE%AE-IGP-Interior-Gateway-Protocol"><span class="toc-number">1.2.3.</span> <span class="toc-text">内部网关协议 IGP(Interior Gateway Protocol)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%96%E9%83%A8%E7%BD%91%E5%85%B3%E5%8D%8F%E8%AE%AEBGP-External-Gateway-Protocol"><span class="toc-number">1.2.4.</span> <span class="toc-text">外部网关协议BGP(External Gateway Protocol)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1CIDR-Classless-Inter-Domain-Routing"><span class="toc-number">1.2.5.</span> <span class="toc-text">无类别域间路由CIDR(Classless Inter-Domain Routing)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#IP%E5%A4%9A%E6%92%AD"><span class="toc-number">1.2.6.</span> <span class="toc-text">IP多播</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%99%9A%E6%8B%9F%E4%B8%93%E7%94%A8%E7%BD%91VPN%E5%92%8C%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2-NAT"><span class="toc-number">1.3.</span> <span class="toc-text">虚拟专用网VPN和网络地址转换 NAT</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BE%8B%E9%A2%98"><span class="toc-number">1.4.</span> <span class="toc-text">例题</span></a></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        网际层
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">张林</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2022-06-25T13:02:12.000Z" itemprop="datePublished">2022-06-25</time>
        
        (Updated: <time datetime="2022-11-25T06:51:00.159Z" itemprop="dateModified">2022-11-25</time>)
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E9%9D%A2%E8%AF%95/">面试</a> › <a class="category-link" href="/categories/%E9%9D%A2%E8%AF%95/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">计算机网络</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link-link" href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/" rel="tag">计算机网络</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h1 id="网际层"><a href="#网际层" class="headerlink" title="网际层"></a>网际层</h1><h2 id="网际协议IP"><a href="#网际协议IP" class="headerlink" title="网际协议IP"></a>网际协议IP</h2><p>网际协议IP是TCP&#x2F;IP体系中两个最主要的协议之一.</p>
<p>与之配套使用的还有四个协议:</p>
<ul>
<li>地址解析协议 ARP Address Resolution Protocol</li>
<li>逆地址解析协议 RARP Reverse Address Resolution Protocol</li>
<li>网际控制报文协议 ICMP Internet Control Message Protocol</li>
<li>网际组管理协议 IGMP Internet Group Management Protocol</li>
</ul>
<h3 id="虚拟互联网络"><a href="#虚拟互联网络" class="headerlink" title="虚拟互联网络"></a>虚拟互联网络</h3><ul>
<li>物理层中继系统 转发器</li>
<li>数据链路层中继系统 网桥</li>
<li>网络层中继系统 路由器</li>
<li>网络层以上的中继系统 网关</li>
</ul>
<h3 id="IP数据包格式"><a href="#IP数据包格式" class="headerlink" title="IP数据包格式"></a>IP数据包格式</h3><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/6-191106153044K1.gif" alt="IP数据报格式示意图"></p>
<ul>
<li>版本 : 有 4（IPv4）和 6（IPv6）两个值；</li>
<li>首部长度 : 占 4 位，因此最大值为 15。值为 1 表示的是 1 个 32 位字的长度，也就是 4 字节。因为固定部分长度为 20 字节，因此该值最小为 5。如果可选字段的长度不是 4 字节的整数倍，就用尾部的填充部分来填充。</li>
<li>区分服务 : 用来获得更好的服务，一般情况下不使用。</li>
<li>总长度 : 包括首部长度和数据部分长度。</li>
<li>生存时间 ：TTL，它的存在是为了防止无法交付的数据报在互联网中不断兜圈子。以路由器跳数为单位，当 TTL 为 0 时就丢弃数据报。</li>
<li>协议 ：指出携带的数据应该上交给哪个协议进行处理，例如 ICMP、TCP、UDP 等。</li>
<li>首部检验和 ：因为数据报每经过一个路由器，都要重新计算检验和，因此检验和不包含数据部分可以减少计算的工作量。</li>
<li>标识 : 在数据报长度过长从而发生分片的情况下，相同数据报的不同分片具有相同的标识符。</li>
<li>片偏移 : 和标识符一起，用于发生分片的情况。片偏移的单位为 8 字节。<ul>
<li>IP数据报分片</li>
</ul>
</li>
</ul>
<h3 id="分类的IP地址"><a href="#分类的IP地址" class="headerlink" title="分类的IP地址"></a>分类的IP地址</h3><ul>
<li>分类<br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/v2-13c1daebb7b5706a847f4e727d9dacde_r.jpg" alt="preview"></li>
<li>无分类<ul>
<li>无分类编址 CIDR 消除了传统 A 类、B 类和 C 类地址以及划分子网的概念，使用网络前缀和主机号来对 IP 地址进行编码，网络前缀的长度可以根据需要变化</li>
<li>一个 CIDR 地址块中有很多地址，一个 CIDR 表示的网络就可以表示原来的很多个网络，并且在路由表中只需要一个路由就可以代替原来的多个路由，减少了路由表项的数量。把这种通过使用网络前缀来减少路由表项的方式称为路由聚合，也称为 构成超网</li>
</ul>
</li>
</ul>
<h3 id="地址解析协议-ARP-与逆地址解析协议RARP"><a href="#地址解析协议-ARP-与逆地址解析协议RARP" class="headerlink" title="地址解析协议 ARP 与逆地址解析协议RARP"></a>地址解析协议 ARP 与逆地址解析协议RARP</h3><ul>
<li><p>ARP实现由IP地址得到MAC地址</p>
<ul>
<li>每个主机都有一个ARP高速缓存表,里面有本局域网上的各主机和路由器的IP地址到MAC地址的映射表</li>
<li>如果主机 A 知道主机 B 的 IP 地址，但是 ARP 高速缓存中没有该 IP 地址到 MAC 地址的映射，此时主机 A 通过广播的方式发送 ARP 请求分组，主机 B 收到该请求后会发送 ARP 响应分组给主机 A 告知其 MAC 地址，随后主机 A 向其高速缓存中写入主机 B 的 IP 地址到 MAC 地址的映射</li>
</ul>
</li>
<li><p>RARP 使只知道自己硬件地址的主机能够知道其 IP 地址(现已很少使用)</p>
</li>
</ul>
<h3 id="网际报文控制协议ICMP"><a href="#网际报文控制协议ICMP" class="headerlink" title="网际报文控制协议ICMP"></a>网际报文控制协议ICMP</h3><ul>
<li>ICMP 是为了更有效地转发 IP 数据报和提高交付成功的机会。它封装在 IP 数据报中，但是不属于高层协议\</li>
<li>ICMP的种类<ul>
<li>ICMP 差错报告报文<ul>
<li>终点不可达 </li>
<li>源点抑制(Source quench)  </li>
<li>时间超过 </li>
<li>参数问题 </li>
<li>改变路由（重定向）(Redirect)</li>
</ul>
</li>
<li>ICMP询问报文<ul>
<li>回送请求和回答报文</li>
<li>时间戳请求和回答报文</li>
</ul>
</li>
<li>应用<ul>
<li>Ping 测试连通性</li>
<li>Traceroute 跟踪一个分组从源点到终点的路径</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="路由选择协议"><a href="#路由选择协议" class="headerlink" title="路由选择协议"></a>路由选择协议</h2><h3 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h3><ul>
<li>静态路由选择策略<ul>
<li>非自适应路由选择，其特点是简单和开销较小，但不能及时适应网络状态的变化</li>
</ul>
</li>
<li>动态路由选择策略<ul>
<li>自适应路由选择，其特点是能较好地适应网络状态的变化，但实现起来较为复杂，开销也比较大</li>
</ul>
</li>
</ul>
<h3 id="自治系统AS-Autonomous-System"><a href="#自治系统AS-Autonomous-System" class="headerlink" title="自治系统AS(Autonomous System)"></a>自治系统AS(Autonomous System)</h3><ul>
<li>在单一的技术管理下的一组路由器，而这些路由器使用一种 AS 内部的路由选择协议和共同的度量以确定分组在该 AS 内的路由，同时还使用一种 AS 之间的路由选择协议用以确定分组在 AS之间的路由</li>
</ul>
<h3 id="内部网关协议-IGP-Interior-Gateway-Protocol"><a href="#内部网关协议-IGP-Interior-Gateway-Protocol" class="headerlink" title="内部网关协议 IGP(Interior Gateway Protocol)"></a>内部网关协议 IGP(Interior Gateway Protocol)</h3><blockquote>
<p>在一个自治系统内部使用的路由选择协议</p>
</blockquote>
<ul>
<li>RIP<ul>
<li>RIP 是一种基于距离向量的路由选择协议。距离是指跳数，直接相连的路由器跳数为 1。跳数最多为 15，超过 15 表示不可达</li>
<li>RIP 按固定的时间间隔仅和相邻路由器交换自己的路由表，经过若干次交换之后，所有路由器最终会知道到达本自治系统中任何一个网络的最短距离和下一跳路由器地址</li>
</ul>
</li>
<li>OSPF<ul>
<li>向本自治系统中的所有路由器发送信息，这种方法是洪泛法</li>
<li>发送的信息就是与相邻路由器的链路状态，链路状态包括与哪些路由器相连以及链路的度量，度量用费用、距离、时延、带宽等来表示</li>
<li>只有当链路状态发生变化时，路由器才会发送信息</li>
</ul>
</li>
</ul>
<h3 id="外部网关协议BGP-External-Gateway-Protocol"><a href="#外部网关协议BGP-External-Gateway-Protocol" class="headerlink" title="外部网关协议BGP(External Gateway Protocol)"></a>外部网关协议BGP(External Gateway Protocol)</h3><ul>
<li>若源站和目的站处在不同的自治系统中，当数据报传到一个自治系统的边界时，就需要使用一种协议将路由选择信息传递到另一个自治系统中</li>
<li>AS 之间的路由选择很困难<ul>
<li>互联网规模很大；</li>
<li>各个 AS 内部使用不同的路由选择协议，无法准确定义路径的度量；</li>
<li>AS 之间的路由选择必须考虑有关的策略，比如有些 AS 不愿意让其它 AS 经过。</li>
</ul>
</li>
<li>BGP 只能寻找一条比较好的路由，而不是最佳路由</li>
<li>每个 AS 都必须配置 BGP 发言人，通过在两个相邻 BGP 发言人之间建立 TCP 连接来交换路由信息</li>
</ul>
<h3 id="无类别域间路由CIDR-Classless-Inter-Domain-Routing"><a href="#无类别域间路由CIDR-Classless-Inter-Domain-Routing" class="headerlink" title="无类别域间路由CIDR(Classless Inter-Domain Routing)"></a>无类别域间路由CIDR(Classless Inter-Domain Routing)</h3><ul>
<li><p>无类别域间路由（CIDR） CIDR是开发<strong>用于帮助减缓IP地址和路由表增大问题</strong>的一项技术<br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/2004486-20200510025702516-1476111227.png" alt="img"></p>
</li>
<li><p>超网合并</p>
<ul>
<li>超网(Super Netting)是与子网类似的概念，IP地址根据子网掩码被分为独立的网络地址和主机地址。与子网划分（把大网络分成若干小网络）相反，它是<strong>把一些小网络组合成一个大网络，就是超网</strong></li>
</ul>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/2269756-20210825171143297-161791354.png" alt="img"></p>
<ul>
<li>如上图，原本两个网段的网络部分不相同，子网掩码是&#x2F;24。将两个网段合并，与子网划分相反，掩码主机位增加，网络位减少，子网掩码向左移动一位，让两个网段的网络位部分相同。合并之后的子网掩码是255.255.254.0，网段是192.168.0.0&#x2F;23.而且合并之后192.168.0.255也可以作为正常IP使用，不再是广播地址，因为其主机位已经不都是1了。（主机位多了一位0）</li>
<li>网段合并规律<ul>
<li>将子网掩码向左移动N位，合并2的N次方个网段。即子网掩码左移1位能够将能够合并两个网段，左移2位，能够合并四个网段，左移3位，能够合并8个网段</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="IP多播"><a href="#IP多播" class="headerlink" title="IP多播"></a>IP多播</h3><ul>
<li>与单播相比，在一对多的通信中，多播可大大节省网络资源<br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220625161948298.png"></li>
</ul>
<h2 id="虚拟专用网VPN和网络地址转换-NAT"><a href="#虚拟专用网VPN和网络地址转换-NAT" class="headerlink" title="虚拟专用网VPN和网络地址转换 NAT"></a>虚拟专用网VPN和网络地址转换 NAT</h2><ul>
<li><p>VPN</p>
<ul>
<li><p>由于 IP 地址的紧缺，一个机构能申请到的 IP 地址数往往远小于本机构所拥有的主机数。并且一个机构并不需要把所有的主机接入到外部的互联网中，机构内的计算机可以使用仅在本机构有效的 IP 地址（专用地址）。</p>
<ul>
<li>有三个专用地址块：<ul>
<li>10.0.0.0 ~ 10.255.255.255</li>
<li>172.16.0.0 ~ 172.31.255.255</li>
<li>192.168.0.0 ~ 192.168.255.255</li>
</ul>
</li>
</ul>
</li>
<li><p>VPN 使用公用的互联网作为本机构各专用网之间的通信载体。专用指机构内的主机只与本机构内的其它主机通信；虚拟指好像是，而实际上并不是，它有经过公用的互联网</p>
</li>
<li><p>VPN的实现主要使用了两种基本技术:<strong>隧道传输</strong>和<strong>加密技术</strong></p>
<ul>
<li>VPN定义了两个内部网络的路由器之间通过Internet建立的通信隧道，使用IP-in-IP封装后在隧道中转发数据报</li>
<li>为了保证保密性，隧道发送路由器把内网IP数据报加密后，封装为外网IP数据报的数据部分在外网中进行传输</li>
<li>隧道接收路由器收到数据报后，从外网数据报中取出数据部分，将数据报解密，还原成内网数据报，然后转发该数据报</li>
</ul>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624165557945.png" alt="image-20220624165557945"></p>
</li>
<li><p>VPN的分类</p>
<ul>
<li>内联网VPN：只是机构内部网络所构成的VPN</li>
<li>外联网VPN：有时一个机构的VPN需要又某些外部机构参加进来，这样的VPN即为外联网VPN</li>
<li>远程接入VPN：公司员工在外地接入公司的VPN，即可远程接入VPN</li>
</ul>
</li>
</ul>
</li>
<li><p>NAT</p>
<ul>
<li><p>显然为每个主机再申请一个全球IP地址是不现实的，需要使用<strong>网络地址转换（Network Address Translation）技术</strong></p>
<ul>
<li>这种方法需要在专用网连接到因特网的路由器上安装NAT软件，装有 NAT 软件的路由器叫做 NAT路由器，它至少有一个有效的外部全球地址 IP</li>
<li>所有使用本地IP地址的主机在和外界通信时都要在 NAT 路由器上将其本地IP地址转换成外网 IP才能和因特网连接</li>
</ul>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624201909104.png"></p>
<ul>
<li>为了更有效的利用NAT路由器的全球IP地址，将传输层的端口号也利用上，这样就可使多个专用网内的主机同时公用一个NAT路由器的全球IP地址，此时叫做<strong>网络地址与端口号转换NAPT（Network Address and Port Translation）</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="例题"><a href="#例题" class="headerlink" title="例题"></a>例题</h2><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624202154348.png" alt="image-20220624202154348"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624202232812.png" alt="image-20220624202232812"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624203254275.png" alt="image-20220624203254275"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624203912640.png" alt="image-20220624203912640"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624204143794.png" alt="image-20220624204143794"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205214717.png" alt="image-20220624205214717"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205723172.png" alt="image-20220624205723172"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205745971.png" alt="image-20220624205745971"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205802040.png" alt="image-20220624205802040"><br><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20220624205810343.png" alt="image-20220624205810343"></p>

  </div>
</article>


    <div class="blog-post-comments">
        <div id="utterances_thread">
            <noscript>Please enable JavaScript to view the comments.</noscript>
        </div>
    </div>


        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Articles</a></li>
         
          <li><a href="/categories/">Category</a></li>
         
          <li><a href="/search/">Search</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E5%B1%82"><span class="toc-number">1.</span> <span class="toc-text">网际层</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E5%8D%8F%E8%AE%AEIP"><span class="toc-number">1.1.</span> <span class="toc-text">网际协议IP</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%99%9A%E6%8B%9F%E4%BA%92%E8%81%94%E7%BD%91%E7%BB%9C"><span class="toc-number">1.1.1.</span> <span class="toc-text">虚拟互联网络</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#IP%E6%95%B0%E6%8D%AE%E5%8C%85%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.1.2.</span> <span class="toc-text">IP数据包格式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E7%B1%BB%E7%9A%84IP%E5%9C%B0%E5%9D%80"><span class="toc-number">1.1.3.</span> <span class="toc-text">分类的IP地址</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AE-ARP-%E4%B8%8E%E9%80%86%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AERARP"><span class="toc-number">1.1.4.</span> <span class="toc-text">地址解析协议 ARP 与逆地址解析协议RARP</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BD%91%E9%99%85%E6%8A%A5%E6%96%87%E6%8E%A7%E5%88%B6%E5%8D%8F%E8%AE%AEICMP"><span class="toc-number">1.1.5.</span> <span class="toc-text">网际报文控制协议ICMP</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B7%AF%E7%94%B1%E9%80%89%E6%8B%A9%E5%8D%8F%E8%AE%AE"><span class="toc-number">1.2.</span> <span class="toc-text">路由选择协议</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">1.2.1.</span> <span class="toc-text">基本概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E6%B2%BB%E7%B3%BB%E7%BB%9FAS-Autonomous-System"><span class="toc-number">1.2.2.</span> <span class="toc-text">自治系统AS(Autonomous System)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E9%83%A8%E7%BD%91%E5%85%B3%E5%8D%8F%E8%AE%AE-IGP-Interior-Gateway-Protocol"><span class="toc-number">1.2.3.</span> <span class="toc-text">内部网关协议 IGP(Interior Gateway Protocol)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%96%E9%83%A8%E7%BD%91%E5%85%B3%E5%8D%8F%E8%AE%AEBGP-External-Gateway-Protocol"><span class="toc-number">1.2.4.</span> <span class="toc-text">外部网关协议BGP(External Gateway Protocol)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1CIDR-Classless-Inter-Domain-Routing"><span class="toc-number">1.2.5.</span> <span class="toc-text">无类别域间路由CIDR(Classless Inter-Domain Routing)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#IP%E5%A4%9A%E6%92%AD"><span class="toc-number">1.2.6.</span> <span class="toc-text">IP多播</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%99%9A%E6%8B%9F%E4%B8%93%E7%94%A8%E7%BD%91VPN%E5%92%8C%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80%E8%BD%AC%E6%8D%A2-NAT"><span class="toc-number">1.3.</span> <span class="toc-text">虚拟专用网VPN和网络地址转换 NAT</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BE%8B%E9%A2%98"><span class="toc-number">1.4.</span> <span class="toc-text">例题</span></a></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/a5656a05d09c/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/a5656a05d09c/&text=网际层"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/a5656a05d09c/&is_video=false&description=网际层"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=网际层&body=Check out this article: https://cheung0-bit.github.io/a5656a05d09c/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/a5656a05d09c/&title=网际层"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/a5656a05d09c/&name=网际层&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/a5656a05d09c/&t=网际层"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
      
        
          2022-2024
            <a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/">
              苏ICP备2022044873号
            </a>
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        
          <!--
       -->
          <li><a href="/">
              Home
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/about/">
              About
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/archives/">
              Articles
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/categories/">
              Category
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/search/">
              Search
            </a></li>
          <!--
     -->
          
      </ul>
    </nav>
  </div>
</footer>
    </div>
    <!-- styles -->


 
  <link
    rel="preload"
    href="/lib/font-awesome/css/all.min.css"
    as="style"
    onload="this.onload=null;this.rel='stylesheet'"
  />
  <noscript
    ><link
      rel="stylesheet"
      href="/lib/font-awesome/css/all.min.css"
  /></noscript>



    <!-- jquery -->
 
  
<script src="/lib/jquery/jquery.min.js"></script>





<!-- clipboard -->

   
    
<script src="/lib/clipboard/clipboard.min.js"></script>

  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

  <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?4484a4a33014b59670c470a6e15a66db";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
        </script>

<!-- Cloudflare Analytics -->

<!-- Umami Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

    <script type="text/javascript">
      var utterances_repo = 'Cheung0-bit/blog-package';
      var utterances_issue_term = 'title';
      var utterances_label = 'Comment';
      var utterances_theme = 'github-dark';

      (function(){
          var script = document.createElement('script');

          script.src = 'https://utteranc.es/client.js';
          script.setAttribute('repo', utterances_repo);
          script.setAttribute('issue-term', 'pathname');
          script.setAttribute('label', utterances_label);
          script.setAttribute('theme', utterances_theme);
          script.setAttribute('crossorigin', 'anonymous');
          script.async = true;
          (document.getElementById('utterances_thread')).appendChild(script);
      }());
  </script>

</body>
</html>
